package com.tfswue.lhj.service;

import org.springframework.context.ApplicationEventPublisher;
import com.tfswue.lhj.event.UserRegisteredEvent;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class EventPublisherService implements ApplicationEventPublisherAware {
    private ApplicationEventPublisher publisher;

    @Override
    public void setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher) {
        this.publisher = applicationEventPublisher;
    }

    // 发布事件的方法
    public void publishUserRegisteredEvent(String username, String email) {

        publisher.publishEvent(new UserRegisteredEvent(this, username, email));
    }
}
